'use strict';

const Controller = require('egg').Controller;

class LoginController extends Controller {
  // 登录
  async login() {
    let res = await this.ctx.service.login.login()
    this.ctx.body = res
  }
  // 解析token
  async gettoken() {
    let token = this.ctx.request.header.token;
    try {
      let decode = this.app.jwt.verify(token, this.app.config.jwt.secret)
      this.ctx.body = decode.username
    } catch (e) {
      this.ctx.body = "token未通过验证"
    }
    // this.ctx.body = "token未通过验证"
  }
  // 修改密码
  async editpassword() {
    let res = await this.ctx.service.login.editpassword()
    this.ctx.body = res
  }
}

module.exports = LoginController;
